<template>
  <catch-table
    :ref="table.ref"
    :headers="table.headers"
    :border="true"
    :search="table.search"
    :filter-params="table.filterParams"
    :hide-pagination="true"
    :form-create="formCreate"
    :actions="table.actions"
    :api-route="table.apiRoute"
    :dialog-width="table.dialog.width"
    default-expand-all
    row-key="id"
    :tree-props="table.tree.props"
  />
</template>
<script>
import renderTable from '@/views/render-table-form'

export default {
  name:'minishop_productcategory',
  mixins: [renderTable],
  data() {
      return {
        tableFrom: 'table/minishop/ProductCategory',
      }
  },
  methods: {
    beforeSubmit(row) {
      if (row.form.parent_id instanceof Array) {
        row.form.parent_id = row.form.parent_id.length > 0 ? row.form.parent_id.pop() : 0
      }
      return row
    },
    afterHandleResponse() {
      this.$http.get('table/minishop/ProductCategory', {params: { only: 'form'}}).then(response => {
        this.formCreate.rule = response.data.form
      })
    },
    sync() {
      this.$http.post('minishop/product/category/sync').then(res => {
        this.$message.success(res.message)
      })
    }
  }
}
</script>

